package com.example.weather_app.base;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

public class HttpUtils {

    public static String loadIndexData(String path){
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        try {
            URL url = new URL(path);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("GET");
            InputStream inputStream = conn.getInputStream();
            byte[] buff = new byte[1024];
            int i = 0;
            while ((i = inputStream.read(buff))!=-1){
                baos.write(buff,0,i);
                int c = i;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return baos.toString();
    }

}
